/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.qdu.servlet;

import com.qdu.entity.Book;
import com.qdu.entity.User;
import com.qdu.service.FavoritesService;
import com.qdu.service.impl.FavoritesServiceImpl;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Ice
 */
@WebServlet("/vbfs")
public class ViewBookFavoritesServlet extends HttpServlet {

    FavoritesService favoritesService = new FavoritesServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("utf-8");

        User user = new User();
        HttpSession session = req.getSession();
        user = (User) session.getAttribute("user");
        int uid = user.getId();// 得到该登录用户的id号

        //2. 调用业务逻辑 ，完成请求处理
        List<Book> BookList = favoritesService.findBookList(uid);

        //3. 生成动态响应
        //为了能够将查到的图书列表显示在Mybook.jsp页面，作为属性添加到请求对象中，并转发请求，从而将数据共享给Mybook.jsp页面
        req.setAttribute("BookFavoritesList", BookList);

        //转发至jsp页面
        //req.getRequestDispatcher("/Mybook.jsp").forward(req, resp);
        req.getRequestDispatcher("/Mybook.jsp").include(req, resp);
    }

}
